<?php
/**
 * @title 365. 水壶问题
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }

class Solution {

    /**
     * @param Integer $jug1Capacity
     * @param Integer $jug2Capacity
     * @param Integer $targetCapacity
     * @return Boolean
     */
    function canMeasureWater($jug1Capacity, $jug2Capacity, $targetCapacity) {
        if($targetCapacity == $jug1Capacity OR $targetCapacity == $jug2Capacity OR $targetCapacity == $jug1Capacity+$jug2Capacity){
            return true;
        } else {}

        /**
         * @since 2024-01-29 2个水壶相等
         */
        if($jug1Capacity == $jug2Capacity){
            return false;
        } else {}

        /**
         * @since 2024-01-29 1号杯水 > 2号杯水
         */
        if($jug1Capacity < $jug2Capacity){
            list($jug1Capacity, $jug2Capacity) = [$jug2Capacity, $jug1Capacity];
        } else {}

        /**
         * @since 2024-01-29 1号杯倒2号杯，剩下的水
         */
        $m1 = $jug1Capacity-$jug2Capacity;

        /**
         * @since 2024-01-29 2号杯倒1号杯，剩下的水
         */
        $m2 = $jug2Capacity - $jug1Capacity%$jug2Capacity;

        /**
         * @since 2024-01-29 1号杯满水和剩余水，匹配目标水
         */
        if($targetCapacity == $jug1Capacity+$m1 OR $targetCapacity == $jug1Capacity+$m2 OR $targetCapacity == $jug1Capacity-$m1 OR $targetCapacity == $jug1Capacity-$m2){
            return true;
        } else {}

        /**
         * @since 2024-01-29 2号杯匹配剩余水
         */
        $m3 = $targetCapacity % $jug2Capacity;
        if($m3 == $m1 OR $m3 == $m1){
            $c = intval($targetCapacity/$jug2Capacity);
            if($c*$jug2Capacity+$m3 <= $jug1Capacity+$jug2Capacity){
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}


/**
 * @url http://127.0.0.1/leetcode/202401/2024.01.29_3.php
 */
$datas = [

];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    /**
     * @since 2024-01-15 超时和错误案例参数
     */
    // $data = $xhprof->FormatArgs("/tmp/leetcode/xxx-xxx.txt");

    // $data[0] = $xhprof->listNode($data[0]);
    // $data[0] = $xhprof->tree($data[0]);
    echo $xhprof->DumpArgs($data);
    echo "\n<hr>\n";

    $obj = new Solution();
    $result = $obj->(...$data);
    echo $xhprof->DumpArgs([$result]);
    // var_dump($result);

    echo "\n<hr>". str_repeat("<br>", 2) . str_repeat(PHP_EOL, 5);
}

// foreach ($datas as $data){
//     $obj = new $data[0][0](...$data[1][0]);
//
//     for ($i=1; $i<count($data[0]); $i++){
//         $func = $data[0][$i];
//         $param = $data[1][$i];
//         $result = $obj->$func(...$param);
//
//         echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
//             if($result === true){
//                 echo "True";
//             } elseif($result === false) {
//                 echo "False";
//             } elseif($result === null) {
//                 echo "Null";
//             } elseif(is_array($result)) {
//                 var_dump($result);
//             } else {
//                 echo $result;
//             }
//         echo PHP_EOL;
//     }
//
//     echo str_repeat(PHP_EOL, 3);
// }
$xhprof->end();
